<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    body{height: 2000px;}
    #toTop{position: fixed;left:0;top:200px;}
  </style>
</head>
<body>
  <h1>一级标题一级标题一级标题一级标题</h1>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <h2>二级标题</h2>
  <input type="button" value="回到顶部" id="toTop">
</body>
<script>

  var toTop = document.getElementById("toTop")

  var t;

  toTop.onclick = function(){
    if( t ) return;
    t = setInterval(function(){
      if(document.documentElement.scrollTop === 0){
        clearInterval(t);
        t = undefined;
      }else{
        document.documentElement.scrollTop -= 200;
      }
    }, 30);
  }
  
</script>
</html>